
/**
\file
Defines the rainbow::culling_state class.
\author Sean Tromans
*/

#include <sun_pre_compiled.hpp>
#include <rainbow/graphics_device/culling_state/culling_state.hpp>

#if !defined(SUN_DISABLE_LUA)
#include <sun/lua/lua.hpp>
#endif

namespace rainbow
{
	/**
	Default Constructor.
	\author Sean Tromans
	*/
	culling_state::culling_state( )
		:		enabled(true)
			,	mode( GL_BACK )
	{
	}

	/**
	Applies any changes from the provided culling_state to OpenGL.
	@param other The currently active blend_state.
	\author Sean Tromans
	*/
	void culling_state::apply( culling_state const & other ) const
	{
		if ( enabled != other.enabled )
		{
			sun::detail::set_state( GL_CULL_FACE, enabled );
		}

		if ( mode != other.mode )
		{
			glCullFace( mode );
		}
	}

	/**
	Exposes the culling_state to lua.
	@param L The Lua State being initialised.
	\author Sean Tromans.
	*/
	void culling_state::lua_interface( lua_State * L )
	{
#if !defined(SUN_DISABLE_LUA)
		luabind::module( L, "rainbow" )
		[
			luabind::class_< culling_state >( "culling_state" )
				.def( luabind::constructor<>( ) )
				.def_readwrite( "enabled", &culling_state::enabled )
				.def_readwrite( "mode", &culling_state::mode )
		];
#else
		NMN_UNUSED( L );
#endif
	}

	/**
	Comparrison operator for culling_states.
	@param lhs The first culling_state being compared.
	@param rhs The second culling_state being compared.
	@return True if the culling_states are equal.
	\author Sean Tromans
	*/
	bool operator == ( culling_state const & lhs, culling_state const & rhs )
	{
		return	lhs.enabled == rhs.enabled
			&&	lhs.mode == rhs.mode;
	}
}
